<?php
	$config = Config::read('config');
	
	// Si han intentado iniciar sesión
	if (Session::isset_data('message'))
	{
		// No mostrar más mensajes
		Session::unset_data('message');
		echo "
			<script type='text/javascript'>
				saySimple('" . ucfirst(_("welcome")) . "', '" . ucfirst(_("cordial greeting")) . " " . Auth::get('account') . "');
			</script>
			";
	}

	if (Auth::is_valid())
	{
		/* Vista parcial de usuario con sesión iniciada */
?>
	<table class="table-login">
		<tr>
			<td><span><?php echo ucfirst(_("user")); ?>:</span></td>
			<td class="td-logout"><?php echo Auth::get('account'); ?></td>
		</tr>
		<tr>
			<td rowspan="3" style="text-align: center;">
				<script type="text/javascript">
				window.addEvent('domready', function()
				{
					var tipsupload = new Tips($$('.tipsupload'), 
					{
						showDelay: 400,
						hideDelay: 400,
						text: "data-text",
						fixed: true,
						onShow: function(tip, el)
						{
							tip.addClass('tipfile');
							tip.setStyle('display', 'block');
						},
						onHide: function(tip, el)
						{
							tip.removeClass('tipfile');
							tip.setStyle('display', 'none');
						}
					});
					
					var spinner = new Spinner('fileimage');
					
					var iFrame = new iFrameFormRequest('form-avatar',
					{
						onRequest: function()
						{
						},
						onComplete: function(responseText)
						{
							spinner.hide();
							response = JSON.decode(responseText, true);
							if ((response != null) && response.error)
								window[response.func]('Error', response.message, 'errorMedium.png');
							else
								document.id('avatar').set('html',responseText);
						}
					});
					
					$("fileimage").addEvent('change', function()
					{
						spinner.show();
						$('form-avatar').fireEvent('submit');
						$('form-avatar').submit();
					}); 

				}); 
				</script>
				<div id="fileimage">
					<?php echo form_tag("profile/image", "id: form-avatar", "name: form-avatar", "method: post", "enctype: multipart/form-data"); ?>
						<?php echo file_field_tag("fileimage", "class: fileimage tipsupload", "title: " . ucfirst(_("avatar")), "data-text: " . ucfirst(_("click on the image to change the avatar"))); ?>
						<?php echo input_field_tag("postfile", "type: hidden", "value: '1'"); ?>
						<?php echo submit_tag(ucfirst(_("sign in")), "style: display: none;"); ?>
					<?php echo end_form_tag(); ?>
					<div id="avatar" class="divfileimage">
						<?php echo img_tag("upload/" . Auth::get('image'), "class: imgavatar"); ?>
					</div>
				</div>
			</td>
			<td class="td-logout"><?php echo  date("d/m/y"); ?><br /><?php echo link_to("", 'text: ' . $config['application']['domain'], 'style: font-size: 8px; text-decoration: none;'); ?></td>
		</tr>
		<tr>
			<td class="td-logout" style="height: 10px;"><?php echo link_to('profile', 'text: ' . ucfirst(_("edit profile"))); ?></td>
		</tr>
		<tr>
			<td class="td-logout" style="height: 10px;"><?php echo link_to('login/logout', 'text: ' . ucfirst(_("sign out"))); ?></td>
		</tr>
	</table>

<?php
	}
	else
	{
		/* Vista parcial de inicio de sesión de usuario */
?>

<?php echo form_tag("login/login", "id: form-login", "name: form-login", "onsubmit: return sendForm(this, false, true);"); ?>
	<table class="table-login">
		<tr>
			<td><span><?php echo ucfirst(_("user")); ?>:</span></td>
			<td class="td-login"><?php echo text_field_tag("user", "class: texto"); ?></td>
		</tr>
		<tr>
			<td><span><?php echo ucfirst(_("password")); ?>:</span></td>
			<td class="td-login"><?php echo password_field_tag("password", "class: texto"); ?></td>
		</tr>
		<tr>
			<td colspan="2"><?php echo submit_tag(ucfirst(_("sign in")), "class: boton"); ?></td>
		</tr>
		<tr>
			<td colspan="2" class="table-td-left"><?php echo link_to("register", ucfirst(_("sign up"))); ?></td>
		</tr>
		<tr>
			<td colspan="2" class="table-td-left"><a href=""><?php echo ucfirst(_("can't access account")); ?></a></td>
		</tr>
	</table>
<?php echo end_form_tag(); ?>

<?php	} ?>
